class x_HUD extends UDKHUD;

//=============================================================================
// Variables:
//=============================================================================
var protected x_PlayerController                  xPC;
var protected x_GameInfo                          xGame;
var protected x_GFx_Menu		                  Main_HUD;
var protected x_GFx_Menu				          MainMenuMovie; // Main menu.

var public x_GFx_MouseCursor		    MouseCursor; // Mouse Cursor
var public vector                       MouseLocation, MouseDirection; //Deprojection
var public Vector2D                     ViewportSize, ScreenCenter; // Screen size and Screen Center coordinates

//=============================================================================
// Functions
//=============================================================================
simulated function PostBeginPlay()
{
	super.PostBeginPlay();

	xPC = x_PlayerController(PlayerOwner);
	xGame = x_GameInfo(WorldInfo.Game);

	ShowMainUserInterface();
	CreateMouseCursor();
	GetViewportSizeAndCenter();
}

/** Shows main user interface. will be used in child classes */
protected function ShowMainUserInterface();

/** Shows/hides menu by pressing ESC. will be used in child classes */
exec function ShowMainMenu();

event PostRender()
{
	super.PostRender();
	Cursor_Deprojection();
}

private function Cursor_Deprojection()
{
	if (MouseCursor != none) Canvas.DeProject(GetGfxMouseCoordinates(), MouseLocation, MouseDirection); 
}

private function CreateMouseCursor()
{
	//if ((Worldinfo.Game.class) != (class'x_GameInfo')) ///delete!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	MouseCursor = new class'x_GFx_MouseCursor';
	MouseCursor.Init( LocalPlayer(xPC.Player) );
	MouseCursor.SetViewScaleMode( SM_ExactFit );
	MouseCursor.SetAlignment( Align_Center );
	MouseCursor.SetPriority(100);
}

/** Used for get Screen size and Screen Center coordinates */
function GetViewportSizeAndCenter()
{
	local Vector2D lViewportSize;
	lViewportSize = MouseCursor.GetViewportSize();
	ViewportSize = lViewportSize;
	ScreenCenter = lViewportSize/2;
}

/** Absolute mouse coordinates from flash movie */
function Vector2d GetGfxMouseCoordinates()
{
	local Vector2d lmousePos;
	
	lmousePos = MouseCursor.GetMouseCoords();

	return lmousePos;
}

/** Relative mouse coordinates from screen center */
function Vector2d GetRelativeMouseCoordinates()
{
	local Vector2d lmousePos;

	lmousePos.X = x_PlayerInput(xPC.PlayerInput).mMouseX;
	lmousePos.Y = x_PlayerInput(xPC.PlayerInput).mMouseY;

	return lmousePos;
}

simulated event Destroyed()
{
	Super.Destroyed();

	if( MouseCursor != none )
	{
		MouseCursor.Close( true );
		MouseCursor = none;
	}
}

//=============================================================================
// Default Properties
//=============================================================================
DefaultProperties
{
	Name="Default__X_HUD"
}